var vm = new Vue({
    el: '#container'
    , data: {
        buttons: {}
        , query: {
            page: 1
            , pageSize: hcCore.pageSize
            , logDate: ''
            , logUser: ''
            , logType: ''
            , logTerminal: ''
            , logIp: ''
            , date: []
        }
        , tableData: {
            records: []
            , total: 0
        }
        , loginTypeArr: []
        , loginTerminalArr: []
        , statusArr: []
    }
    , mounted: async function () {
        const me = this;
        await me.getLoginType();
        await me.getLoginTerminal();
        await me.getStatus();
        me.buttons = await hcCore.getPowerButton();
        if (me.buttons.hasQuery) {
            me.onQuery();
        }
    }
    , computed: {
        loginType: function () {
            let result = {};
            this.loginTypeArr.forEach(item => {
                if (item.sub_value) {
                    result[item.sub_value] = item.sub_name;
                }
            });
            return result;
        }
        , loginTerminal: function () {
            let result = {};
            this.loginTerminalArr.forEach(item => {
                if (item.sub_value) {
                    result[item.sub_value] = item.sub_name;
                }
            });
            return result;
        }
        , status: function () {
            let result = {};
            this.statusArr.forEach(item => {
                if (item.sub_value) {
                    result[item.sub_value] = item.sub_name;
                }
            });
            return result;
        }
    }
    , methods: {
        onQuery: function () {
            let me = this;
            console.log(me.query.date);
            hcCore.post({
                url: '/LogLogin/List'
                , param: {
                    page: me.query.page
                    , page_size: me.query.pageSize
                    , start_date: (me.query.date && me.query.date.length > 0) ? me.query.date[0] : null
                    , end_date: (me.query.date && me.query.date.length > 1) ? me.query.date[1] : null
                    , log_user: me.query.logUser
                    , log_type: me.query.logType
                    , log_terminal: me.query.logTerminal
                    , log_ip: me.query.logIp
                }
                , success: function (rsp) {
                    me.tableData.records = rsp.data;
                    me.tableData.total = rsp.total;
                }
            })
        }
        , onPageChange: function (page) {
            this.query.page = page;
            this.onQuery();
        }
        , getLoginType: async function () {
            let me = this;
            await hcCore.post({
                url: '/SysSetting/GetLoginType'
                , success: async function (rsp) {
                    me.loginTypeArr = rsp.data;
                    me.loginTypeArr.unshift({
                        sub_value: ''
                        , sub_name: '请选择'
                    });
                }
            });
        }
        , getLoginTerminal: async function() {
            let me = this;
            await hcCore.post({
                url: '/SysSetting/GetLoginTerminal'
                , success: async function (rsp) {
                    me.loginTerminalArr = rsp.data;
                    me.loginTerminalArr.unshift({
                        sub_value: ''
                        , sub_name: '请选择'
                    });
                }
            });
        }
        , getStatus: async function () {
            let me = this;
            await hcCore.post({
                url: '/SysSetting/GetStatus'
                , success: async function (rsp) {
                    me.statusArr = rsp.data;
                    me.statusArr.unshift({
                        sub_value: ''
                        , sub_name: '请选择'
                    });
                }
            });
        }
        , getStatusClass: function (status) {
            if (status == 0) {
                return 'el-tag el-tag--danger el-tag--light';
            }
            else {
                return '';
            }
        }
        , getParams: function () {
            let param = {};
            this.edit.fields.forEach((item, index) => {
                param[item.name] = item.value;
            });
            return param;
        }
        , resetParams: function (obj) {
            obj.forEach(item => {
                item.value = '';
                item.disabled = false;
            });
        }
        , recordIndex: function (index) {
            return (this.query.page - 1) * this.query.pageSize + index + 1;
        }
    }
});